/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-12-11 12:32:37
 * @LastEditors: GGB
 * @LastEditTime: 2021-12-11 12:41:37
 */
// 过滤操作
import { reactive, computed } from "vue";
const filters = {
  all(todos) {
    return todos;
  },
  active(todos) {
    return todos.filter(todo => !todo.completed);
  },
  completed(todos) {
    return todos.filter(todo => todo.completed);
  },
};

export function useFilters(todos) {
  const filterState = reactive({
    visibility: "all",
    filterItems: [
      {
        value: "all",
        label: "全部",
      },
      {
        value: "completed",
        label: "完成",
      },
      {
        value: "active",
        label: "进行中",
      },
    ],
    filterdTodos: computed(() => {
      return filters[filterState.visibility](todos.value);
    }),
  });

  return filterState;
}
